package cn.buk.tms.eotms.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *火车票退票订单
 * @author yfdai
 * @date 2019-10-13
 */
@Entity
@Table(name = "train_refund_order", uniqueConstraints = @UniqueConstraint(name = "uk_train_refund_order", columnNames = {"enterprise_id", "order_no"}))
public class TrainRefundOrder {

    /**
     * 待处理
     */
    public static final int STATUS_WAITING = 0;
    /**
     * 处理中
     */
    public static final int STATUS_PROCESSING = 1;
    /**
     * 处理完成
     */
    public static final int STATUS_DONE = 2;
    /**
     * 已取消
     */
    public static final int STATUS_CANCELED = 4;

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;

    @Column(name = "enterprise_id")
    private int enterpriseId;

    /**
     * 订单号
     */
    @Column(name = "order_no", length = 10)
    private String orderNo;

    /**
     * 原火车票订单
     */
    @Column(name = "train_order_no", length = 10)
    private String trainOrderNo;

    @Column(name = "external_order_no", length = 20)
    private String externalOrderNo;

    /**
     * 酒店订单状态
     * 0 - 待预定
     * 4 - 已取消
     * 1 - 处理中
     * 2 - 已确认
     * 8 - 订单完成
     */
    private int status;

    /**
     * 创建此账单的用户名
     */
    @Column(length = 32)
    private String operator;

    /**
     * 出票员
     */
    @Column(length = 32)
    private String ticketer;

    /**
     * 收款员（如果是月结订单，该值为空)
     */
    @Column(length = 32)
    private String cashier;


    /**
     * 客户类型：
     * 0 - 散客（对应的customer, customerId 为 null）
     * 1 - 企业客户（对应的customer, customerId 有值）
     */
    @Column(name = "customer_type")
    private int customerType;

    /**
     * 为该客户预定的酒店
     */
    @ManyToOne
    @JoinColumn(name="customer_id", foreignKey = @ForeignKey(name = "fk_train_refund_order_customer"))
    private Customer customer;

    @Column(name = "customer_id", insertable = false, updatable = false)
    private Integer customerId;

    /**
     * 成本中心
     */
    @Column(name = "cost_center", length = 50)
    private String costCenter;

    @Column(name = "project_name", length = 50)
    private String projectName;


    /**
     * 付款方式
     */
    @Column(length = 2, name = "pay_mode")
    private String payMode = "8";



    //姓名 车次 出发地 目的地 日期 座位等级 价格 服务费

    /**
     * 姓名
     */
    @Column(name="psg_name", length=50)
    private String passengerName;

    @Column(name = "psg_count")
    private Integer psgCount;

    @OneToMany(mappedBy="orderInfo", cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    private List<TrainRefundOrderPassenger> passengers;

    /**
     * 车次
     */
    @Column(name="train_no", length=50)
    private String trainNo;

    /**
     * 出发地
     */
    @Column(length=50)
    private String dcity;

    /**
     * 目的地
     */
    @Column(length=50)
    private String acity;

    /**
     * 日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    @Temporal(TemporalType.DATE)
    private Date ddate;

    @Column(length = 10)
    private String dtime;

    @Column(length = 10)
    private String atime;

    /**
     * 座位等级
     */
    @Column(name = "seat_class", length = 50)
    private String seatClass;

    /**
     * 价格
     */
    private double price;

    private double cost;

    /**
     * 服务费
     */
    @Column(name = "service_charge")
    private double serviceCharge;

    @Column(name = "total_amount")
    private double totalAmount;

    @Column(name = "total_cost")
    private double totalCost;

    private double profit;


    private String remark;

    /**
     * 是否已付款
     */
    @Column(name = "be_paid", length = 1)
    private String bePaid;


    /**
     * 保存数据库的时间：系统自动生成
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="create_time", insertable = false, updatable = false)
    private Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_update", insertable = false)
    private Date lastUpdate;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public Customer getCustomer() {
        return this.customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String getPayMode() {
        return payMode;
    }

    public void setPayMode(String payMode) {
        this.payMode = payMode;
    }

    public String getPassengerName() {
        return passengerName;
    }

    public void setPassengerName(String passengerName) {
        this.passengerName = passengerName;
    }

    public String getTrainNo() {
        return trainNo;
    }

    public void setTrainNo(String trainNo) {
        this.trainNo = trainNo;
    }

    public String getDcity() {
        return dcity;
    }

    public void setDcity(String dcity) {
        this.dcity = dcity;
    }

    public String getAcity() {
        return acity;
    }

    public void setAcity(String acity) {
        this.acity = acity;
    }

    public Date getDdate() {
        return ddate;
    }

    public void setDdate(Date ddate) {
        this.ddate = ddate;
    }

    public String getSeatClass() {
        return seatClass;
    }

    public void setSeatClass(String seatClass) {
        this.seatClass = seatClass;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getServiceCharge() {
        return serviceCharge;
    }

    public void setServiceCharge(double serviceCharge) {
        this.serviceCharge = serviceCharge;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getBePaid() {
        return bePaid;
    }

    public void setBePaid(String bePaid) {
        this.bePaid = bePaid;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public String getTicketer() {
        return ticketer;
    }

    public void setTicketer(String ticketer) {
        this.ticketer = ticketer;
    }

    public String getCashier() {
        return cashier;
    }

    public void setCashier(String cashier) {
        this.cashier = cashier;
    }

    public int getCustomerType() {
        return customerType;
    }

    public void setCustomerType(int customerType) {
        this.customerType = customerType;
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public String getCostCenter() {
        return costCenter;
    }

    public void setCostCenter(String costCenter) {
        this.costCenter = costCenter;
    }

    public String getProjectName() {
        return projectName == null ? "": projectName.trim();
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public double getTotalCost() {
        return totalCost;
    }

    public void setTotalCost(double totalCost) {
        this.totalCost = totalCost;
    }

    public double getProfit() {
        return profit;
    }

    public void setProfit(double profit) {
        this.profit = profit;
    }

    public int getPsgCount() {
        return psgCount == null ? 1 : psgCount;
    }

    public void setPsgCount(Integer psgCount) {
        this.psgCount = psgCount;
    }

    public List<TrainRefundOrderPassenger> getPassengers() {
        if (passengers == null) {
          passengers = new ArrayList<>();
        }
        return passengers;
    }

    public void setPassengers(List<TrainRefundOrderPassenger> passengers) {
        this.passengers = passengers;
    }

    public String getExternalOrderNo() {
        return externalOrderNo;
    }

    public void setExternalOrderNo(String externalOrderNo) {
        this.externalOrderNo = externalOrderNo;
    }

    public String getDtime() {
        return dtime;
    }

    public void setDtime(String dtime) {
        this.dtime = dtime;
    }

    public String getAtime() {
        return atime;
    }

    public void setAtime(String atime) {
        this.atime = atime;
    }

    public String getTrainOrderNo() {
        return trainOrderNo;
    }

    public void setTrainOrderNo(String trainOrderNo) {
        this.trainOrderNo = trainOrderNo;
    }
}
